import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

import { nodePolyfills } from 'vite-plugin-node-polyfills';

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    nodePolyfills()
  ],
  server: {
    host: '0.0.0.0',
    port: 5173,
    open: true,
    proxy: {
      '/api': {
        target: 'https://api.siliconflow.cn',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, ''),
        configure: (proxy, options) => {
          proxy.on('error', (err, req, res) => {
            console.log('代理错误:', err);
          });
          proxy.on('proxyReq', (proxyReq, req, res) => {
            console.log('请求路径:', proxyReq.path);
            console.log('请求方法:', proxyReq.method);
          });
          proxy.on('proxyRes', (proxyRes, req, res) => {
            console.log('响应状态:', proxyRes.statusCode);
          });
        },
        timeout: 60000 // 设置代理超时时间为 60 秒
      }
    }
  }
})
